#include <stdio.h>

typedef int ElemType;

typedef enum {
    OK,
    ERROR
} Status;

#define MAXSIZE 1000
typedef struct{
    ElemType data;
    int cur;
} Component, StaticLinkList[MAXSIZE];

Status InitList(Component *space)
{
    int i;
    for (i = 0; i < MAXSIZE; ++i) {
        space[i].cur = i + 1;
    }
    space[MAXSIZE - 1].cur = 0;
    return OK;
}

int Malloc_SLL(StaticLinkList space)
{
    int i = space[0].cur;
    if (space[0].cur) {
        space[0].cur = space[i].cur;
    }
    return i;
}

void Free_SSL(Component *space, int k)
{
    space[k].cur = space[0].cur;
    space[0].cur = k;
}

int ListLength(StaticLinkList L)
{
    int j = 0;
    int i = L[MAXSIZE - 1].cur;
    while (i) {
        i = L[i].cur;
        ++j;
    }
    return j;
}

Status ListInsert(Component *L, int i, ElemType e)
{
    int j, k, l;
    k = MAXSIZE - 1;
    if (i < 1 || i > ListLength(L) + 1) {
        return ERROR;
    }
    j = Malloc_SLL(L);
    if (j) {
        L[j].data = e;
        for (l = 1; l <= i - 1; ++l) {
            k = L[k].cur;
        }
        L[j].cur = L[k].cur;
        L[k].cur = j;
        return OK;
    }
    return ERROR;
}

Status ListDelete(Component *L, int i)
{
    int j, k;
    if (i < 1 || i > ListLength(L) + 1) {
        return ERROR;
    }
    k = MAXSIZE - 1;
    for (j = 1; j <= i -1; ++j) {
        k = L[k].cur;
    }
    j = L[k].cur;
    L[k].cur = L[j].cur;
    Free_SSL(L, j);
    return OK;
}

int main()
{
    StaticLinkList L;
    printf("size: %d", sizeof(Component));
    printf("size: %d", Malloc_SLL(L));
    printf("size: %d", Malloc_SLL(L));
    return 0;
}

